// pages/selectAccount/index.js
var util = require('../../utils/util.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    showBankCard:false,
    showWeChat:false,
    bankAccount:"",
    bankBranch:"",
    accountName:"",
    weChatNickname:"",
    weChatNumber:""
  },
  toModify(){
    wx.navigateTo({
      url: '/pages/drawInfo/index',
    })
  },

  addBankCard() {
    wx.navigateTo({
      url: '/pages/addBankCard/index',
    })
  },

  addWeChat() {
    wx.navigateTo({
      url: '/pages/addWeChat/index',
    })
  },

  selectAccount(e){
    console.log(e);
    let selectType = e.currentTarget.dataset.type;
    wx.setStorageSync('SelectAccount', selectType);
    wx.navigateBack({
      delta: 1
    })
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
  },

  init:function(){
    var that = this;
    let userInfo = wx.getStorageSync('userInfo');
    util.http({
      url: '/api/miniwechat/center/bank_info',
      data: {
        user_id: userInfo.user_id
      }
    }).then(res => {
      console.log(res);
      if(res) {
        if (res.bank_account) {
          that.setData({
            bankAccount: res.bank_account,
            bankBranch: res.bank_branch,
            accountName: res.bank_name.substr(1),
            showBankCard: true,
          })
        }
        if (res.wechat_account) {
          that.setData({
            weChatNumber: res.wechat_account,
            weChatNickname: res.wechat_nickname.substr(1),
            showWeChat: true
          })
        }
      }
     
    
    }).catch(ex => {
      wx.showToast({
        title: String(ex),
        icon: 'none',
        duration: 2000
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.init()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})